package com.it.you.base.stream;

import cn.hutool.core.date.DateUtil;
import com.it.you.pojo.Student;
import com.it.you.pojo.Worker;
import lombok.SneakyThrows;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

public class StreamTest4 {

    @SneakyThrows
    public static void main(String[] args) {

        List<Student> students = new ArrayList<>();
        Student s1 = new Student("you", 18, new Date(DateUtil.parseDate("1992-06-19").getTime()), "武汉", new BigDecimal("50000000"));
        Student s2 = new Student("you", 18, new Date(DateUtil.parseDate("1994-03-14").getTime()), "运城", new BigDecimal("20000000"));
        Student s3 = new Student("tian", 18, new Date(DateUtil.parseDate("1965-10-23").getTime()), "黄陂", new BigDecimal("20000000"));
        Student s4 = new Student("ma", 18, new Date(DateUtil.parseDate("1964-08-03").getTime()), "武汉", new BigDecimal("40000000"));

        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);

        List<Worker> collect = students.stream().map(Student::getAge).distinct()
                .map(v -> {
                            Worker w = new Worker();
                            w.setAge(v);
                            w.setName("haha");
                            return w;
                        }
                ).collect(Collectors.toList());
        System.out.println(collect);

        List<Worker> collect1 = students.stream().map(v -> {
                    Worker w = new Worker();
                    w.setAge(v.getAge());
                    w.setName("haha");
                    return w;
                }
        ).collect(Collectors.toList());
        System.out.println(collect1);

        List<Worker> workers = students.stream().map(v -> v.getName() + "," + v.getAge()).distinct().map(v -> {
            String[] split = v.split(",");
            Worker worker = new Worker();
            worker.setName(split[0]);
            worker.setAge(Integer.parseInt(split[1]));
            return worker;
        }).collect(Collectors.toList());
        System.out.println(workers);
    }

}
